package com.whj.serviceprice.controller;


import com.whj.internalcommon.dto.PriceRules;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.request.PriceRulesNewRequest;
import com.whj.serviceprice.service.IPriceRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author whj
 * @since 2023-01-29
 */
@RestController
@RequestMapping("/price-rules")
public class PriceRulesController {

    @Autowired
    private IPriceRulesService iPriceRulesService;

    /**
     * 添加计价规则
     *
     * @param priceRules
     * @return
     */
    @PostMapping("/add")
    public ResponseResult add(@RequestBody PriceRules priceRules) {
        return iPriceRulesService.add(priceRules);
    }

    /**
     * 修改计价规则
     *
     * @param priceRules
     * @return
     */
    @PostMapping("/edit")
    public ResponseResult edit(@RequestBody PriceRules priceRules) {
        return iPriceRulesService.edit(priceRules);
    }

    /**
     * 查询最新的计价规则
     *
     * @param fareType
     * @return
     */
    @GetMapping("/get-newest-version")
    public ResponseResult<PriceRules> getNewestVersion(@RequestParam String fareType) {
        return iPriceRulesService.getNewestVersion(fareType);
    }

    /**
     * 判断计价规则是否是最新版本
     *
     * @param priceRulesNewRequest
     * @return
     */
    @PostMapping("/is-new")
    public ResponseResult<Boolean> getVersionIsNew(@RequestBody PriceRulesNewRequest priceRulesNewRequest) {
        return iPriceRulesService.getVersionIsNew(priceRulesNewRequest.getFareType(),priceRulesNewRequest.getFareVersion());
    }

    /**
     * 根据城市编码和车型查询计价规则是否存在
     *
     * @param priceRules
     * @return
     */
    @PostMapping("/if-exists")
    public ResponseResult<Boolean> ifExists(@RequestBody PriceRules priceRules) {
        return iPriceRulesService.ifExists(priceRules);
    }
}
